package com.youlai.boot.modules.exhibition.controller;

import com.youlai.boot.common.result.PageResult;
import com.youlai.boot.common.result.Result;
import com.youlai.boot.modules.exhibition.model.ExhibitionForm;
import com.youlai.boot.modules.exhibition.model.ExhibitionPageQuery;
import com.youlai.boot.modules.exhibition.model.ExhibitionVO;
import com.youlai.boot.modules.exhibition.service.ExhibitionService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;

@Tag(name = "展会接口")
@RestController
@RequestMapping("/api/v1/exhibition")
@RequiredArgsConstructor
public class ExhibitionController {

    private final ExhibitionService exhibitionService;

    @Operation(summary = "展会分页列表")
    @GetMapping("/page")
    public PageResult<ExhibitionVO> listExhibitions(ExhibitionPageQuery query) {
        Page<ExhibitionVO> result = exhibitionService.getExhibitionPage(query);
        return PageResult.success(result);
    }

    @Operation(summary = "展会详情")
    @GetMapping("/{id}")
    public Result<ExhibitionVO> getExhibition(@PathVariable Long id) {
        ExhibitionVO exhibition = exhibitionService.getExhibitionById(id);
        return Result.success(exhibition);
    }

    @Operation(summary = "添加展会")
    @PostMapping
    public Result<Long> addExhibition(@Valid @RequestBody ExhibitionForm exhibition) {
        Long id = exhibitionService.saveExhibition(exhibition);
        return Result.success(id);
    }

    @Operation(summary = "修改展会")
    @PutMapping("/{id}")
    public Result<Boolean> updateExhibition(
            @PathVariable Long id,
            @Valid @RequestBody ExhibitionForm exhibition) {
        exhibition.setId(id);
        exhibitionService.updateExhibition(exhibition);
        return Result.success(true);
    }

    @Operation(summary = "删除展会")
    @DeleteMapping("/{id}")
    public Result<Boolean> deleteExhibition(@PathVariable Long id) {
        boolean result = exhibitionService.deleteExhibition(id);
        return Result.judge(result);
    }
}